🧪 test: add test for non-Name annotated assignment targets#8
Conversation
Adds a test to `tests/test_ast_parser.py` to ensure that `ASTParser._handle_annotated_assign` correctly ignores annotated assignments when the target is not an `ast.Name` (e.g., `self.x: int = 1`). Also fixes the `sample_type_aliases.py` fixture which had an incorrect syntax for pre-3.12 type aliases. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
Adds coverage for an AST parsing edge case around annotated assignments with non-ast.Name targets, and updates a real-file fixture to better represent pre-/post-Python 3.12 type alias styles used by the parser tests.
Changes:
- Add a unit test asserting that
ast.AnnAssignwith an attribute target (e.g.,self.x: int = 1) yields no extracted symbols. - Update the
sample_type_aliases.pyfixture to use pre-3.12TypeAlias-annotated assignments for the “pre-3.12” section.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/test_ast_parser.py | Adds a new edge-case test for annotated assignments with attribute targets. |
| tests/fixtures/sample_type_aliases.py | Adjusts the “pre-3.12” type alias fixtures to use TypeAlias annotations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Pre-3.12 style type aliases (X: TypeAlias = Y) | ||
| type FilePath = str | Path | ||
| type ModuleName = str | ||
| type RulePattern = str | ||
| type ExportName = str | ||
| type ErrorMessage = str | ||
| type ConfigDict = dict[str, str | int | bool | list[str]] | ||
| type NamePair = tuple[str, str] | ||
| from typing import TypeAlias | ||
|
|
||
| FilePath: TypeAlias = str | Path | ||
| ModuleName: TypeAlias = str |
| # Pre-3.12 style type aliases (X: TypeAlias = Y) | ||
| type FilePath = str | Path | ||
| type ModuleName = str | ||
| type RulePattern = str | ||
| type ExportName = str | ||
| type ErrorMessage = str | ||
| type ConfigDict = dict[str, str | int | bool | list[str]] | ||
| type NamePair = tuple[str, str] | ||
| from typing import TypeAlias | ||
|
|
||
| FilePath: TypeAlias = str | Path | ||
| ModuleName: TypeAlias = str | ||
| RulePattern: TypeAlias = str | ||
| ExportName: TypeAlias = str | ||
| ErrorMessage: TypeAlias = str | ||
| ConfigDict: TypeAlias = dict[str, str | int | bool | list[str]] | ||
| NamePair: TypeAlias = tuple[str, str] |
Adds a test to `tests/test_ast_parser.py` to ensure that `ASTParser._handle_annotated_assign` correctly ignores annotated assignments when the target is not an `ast.Name` (e.g., `self.x: int = 1`). Also fixes a CI failure caused by the `sample_type_aliases.py` fixture. The file uses `UP040` (pre-3.12 `TypeAlias` syntax) on purpose to test backward compatibility, but `ruff` was reporting an error for it. We added `# ruff: noqa: UP040` to suppress the linting error for this specific file. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…331684 Signed-off-by: Adam Poulemanos <89049923+bashandbone@users.noreply.github.com>
🎯 What: The testing gap addressed is the missing edge case in the AST parser for annotated assignments (
ast.AnnAssign) when the target is an attribute (ast.Attribute) rather than a simple name (ast.Name). Feeding code likeself.x: int = 1into the parser triggers this logic.📊 Coverage: The scenario of an annotated assignment target that is not a plain name (e.g.,
self.x: int = 1) is now fully tested and verified to correctly return no symbols.✨ Result: Increased test coverage and assurance that complex annotated assignments will not crash the AST parser or result in erroneously extracted exportable symbols. The test explicitly verifies that the correct branch is taken and handled gracefully.
PR created automatically by Jules for task 12845267801571331684 started by @bashandbone